package com.gorillalogic.scrummonkey.dms {
	import mx.rpc.AsyncToken;

	public class ReleaseService extends _Super_ReleaseService {
		public static var service:ReleaseService = new ReleaseService();

		public override function deleteRelease(release:Release):AsyncToken {
			//first, re-assign any objectives to the parent project
			release.objectives.toArray().forEach(
				function(o:Objective, idx:int, items:Array):void {
					o.unassign(release);
				});

			//second, delete any child iteration
			var iterations:Array = release.iterations.toArray();
			release.iterations.removeAll();
			iterations.forEach(
				function(iteration:Iteration, index:int, releases:Array):void {
					IterationService.service.deleteIteration(iteration);
				});

			//lastly, delete the release
			return super.deleteRelease(release);
		}
	}
}
